<div class="refentry" title="glBlendFunc"><a id="glBlendFunc"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>glBlendFunc — specify pixel arithmetic</p></div><div class="refsynopsisdiv" title="C Specification"><h2>C Specification</h2><div class="funcsynopsis"><table class="funcprototype-table"><tr><td><code class="funcdef">void <b class="fsfunc">glBlendFunc</b>(</code></td><td>GLenum <var class="pdparam">sfactor</var>, </td></tr><tr><td> </td><td>GLenum <var class="pdparam">dfactor</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1" title="Parameters"><a id="parameters"></a><h2>Parameters</h2><div class="variablelist"><dl><dt><span class="term">
		    <em class="parameter"><code>sfactor</code></em>
		</span></dt><dd><p>
		    Specifies how the red, green, blue, and alpha
		    source blending factors are computed. The following
		    symbolic constants are accepted:
		    <code class="constant">GL_ZERO</code>,
		    <code class="constant">GL_ONE</code>,
		    <code class="constant">GL_DST_COLOR</code>,
		    <code class="constant">GL_ONE_MINUS_DST_COLOR</code>,
		    <code class="constant">GL_SRC_ALPHA</code>,
		    <code class="constant">GL_ONE_MINUS_SRC_ALPHA</code>,
		    <code class="constant">GL_DST_ALPHA</code>,
		    <code class="constant">GL_ONE_MINUS_DST_ALPHA</code>, and
		    <code class="constant">GL_SRC_ALPHA_SATURATE</code>.
		    The initial value is <code class="constant">GL_ONE</code>.
		    </p></dd><dt><span class="term">
		    <em class="parameter"><code>dfactor</code></em>
		</span></dt><dd><p>Specifies how the red, green, blue, and alpha
		    destination blending factors are computed. Eight symbolic
		    constants are accepted:
		    <code class="constant">GL_ZERO</code>,
		    <code class="constant">GL_ONE</code>,
		    <code class="constant">GL_SRC_COLOR</code>,
		    <code class="constant">GL_ONE_MINUS_SRC_COLOR</code>,
		    <code class="constant">GL_SRC_ALPHA</code>,
		    <code class="constant">GL_ONE_MINUS_SRC_ALPHA</code>,
		    <code class="constant">GL_DST_ALPHA</code>, and
		    <code class="constant">GL_ONE_MINUS_DST_ALPHA</code>. The initial value is
		    <code class="constant">GL_ZERO</code>.</p></dd></dl></div></div><div class="refsect1" title="Description"><a id="description"></a><h2>Description</h2><p>Pixels can be drawn using a function that blends the
	incoming (source) values with the values that are already in
	the color buffer (the destination values). Use
	<a class="citerefentry" href="glEnable"><span class="citerefentry"><span class="refentrytitle">glEnable</span></span></a> and
	<a class="citerefentry" href="glDisable"><span class="citerefentry"><span class="refentrytitle">glDisable</span></span></a>
	with argument <code class="constant">GL_BLEND</code>
	to enable and disable blending.
	Blending is initially disabled.
	</p><p>
	<code class="function">glBlendFunc</code>
	defines the operation of blending when it is enabled.
	<em class="parameter"><code>sfactor</code></em>
	specifies which of eleven methods is used to scale the source color components.
	<em class="parameter"><code>dfactor</code></em>
	specifies which of ten methods is used to scale the destination color components.
	The eleven possible methods are described in the following table.
	Each method defines four scale factors, one each for red, green, blue, and alpha.
	</p><p>In the table and in subsequent equations, source and
	destination color components are referred to as
	<math overflow="scroll"><mrow><mo>(</mo>
	    <msub><mi>R</mi><mi>s</mi></msub><mo>,</mo>
	    <msub><mi>G</mi><mi>s</mi></msub><mo>,</mo>
	    <msub><mi>B</mi><mi>s</mi></msub><mo>,</mo>
	    <msub><mi>A</mi><mi>s</mi></msub>
	<mo>)</mo></mrow></math>
	and
	<math overflow="scroll"><mrow><mo>(</mo>
	    <msub><mi>R</mi><mi>d</mi></msub><mo>,</mo>
	    <msub><mi>G</mi><mi>d</mi></msub><mo>,</mo>
	    <msub><mi>B</mi><mi>d</mi></msub><mo>,</mo>
	    <msub><mi>A</mi><mi>d</mi></msub>
	<mo>)</mo></mrow></math>.
	They are understood to have integer values between 0 and
	<math overflow="scroll"><mrow><mo>(</mo>
	    <msub><mi>k</mi><mi>R</mi></msub><mo>,</mo>
	    <msub><mi>k</mi><mi>G</mi></msub><mo>,</mo>
	    <msub><mi>k</mi><mi>B</mi></msub><mo>,</mo>
	    <msub><mi>k</mi><mi>A</mi></msub>
	<mo>)</mo></mrow></math>,
	where</p><div class="informalequation"><math overflow="scroll">
	    <msub><mi>k</mi><mi>c</mi></msub>
	    <mo>=</mo>
	    <msup><mn>2</mn><msub><mi>m</mi><mi>c</mi></msub></msup>
	    <mo>-</mo>
	    <mn>1</mn>
	</math></div><p> and
	<math overflow="scroll"><mrow><mo>(</mo>
	    <msub><mi>m</mi><mi>R</mi></msub><mo>,</mo>
	    <msub><mi>m</mi><mi>G</mi></msub><mo>,</mo>
	    <msub><mi>m</mi><mi>B</mi></msub><mo>,</mo>
	    <msub><mi>m</mi><mi>A</mi></msub>
	<mo>)</mo></mrow></math>
	is the number of red, green, blue, and alpha bitplanes.</p><p>Source and destination scale factors are referred to as
	<math overflow="scroll"><mrow><mo>(</mo>
	    <msub><mi>s</mi><mi>R</mi></msub><mo>,</mo>
	    <msub><mi>s</mi><mi>G</mi></msub><mo>,</mo>
	    <msub><mi>s</mi><mi>B</mi></msub><mo>,</mo>
	    <msub><mi>s</mi><mi>A</mi></msub>
	<mo>)</mo></mrow></math>
	and
	<math overflow="scroll"><mrow><mo>(</mo>
	    <msub><mi>d</mi><mi>R</mi></msub><mo>,</mo>
	    <msub><mi>d</mi><mi>G</mi></msub><mo>,</mo>
	    <msub><mi>d</mi><mi>B</mi></msub><mo>,</mo>
	    <msub><mi>d</mi><mi>A</mi></msub>
	<mo>)</mo></mrow></math>.

	The scale factors described in the table, denoted
	<math overflow="scroll"><mrow><mo>(</mo>
	    <msub><mi>f</mi><mi>R</mi></msub><mo>,</mo>
	    <msub><mi>f</mi><mi>G</mi></msub><mo>,</mo>
	    <msub><mi>f</mi><mi>B</mi></msub><mo>,</mo>
	    <msub><mi>f</mi><mi>A</mi></msub>
	<mo>)</mo></mrow></math>,
	represent either source or destination factors. All scale
	factors have range [0, 1].</p><div class="informaltable"><table><colgroup><col /><col /></colgroup><thead><tr><th>Parameter</th><th class="center">
			    <math overflow="scroll"><mrow><mo>(</mo>
				<msub><mi>f</mi><mi>R</mi></msub><mo>,</mo>
				<msub><mi>f</mi><mi>G</mi></msub><mo>,</mo>
				<msub><mi>f</mi><mi>B</mi></msub><mo>,</mo>
				<msub><mi>f</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</th></tr></thead><tbody><tr><td>
			    <code class="constant">GL_ZERO</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow><mo>(</mo>
				<mn>0</mn><mo>,</mo>
				<mn>0</mn><mo>,</mo>
				<mn>0</mn><mo>,</mo>
				<mn>0</mn>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_ONE</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow><mo>(</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_SRC_COLOR</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow><mo>(</mo>
				<msub><mi>R</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>R</mi></msub><mo>,</mo>
				<msub><mi>G</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>G</mi></msub><mo>,</mo>
				<msub><mi>B</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>B</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_ONE_MINUS_SRC_COLOR</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow>
			    <mo>(</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn>
			    <mo>)</mo>
			    <mo>-</mo>
			    <mo>(</mo>
				<msub><mi>R</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>R</mi></msub><mo>,</mo>
				<msub><mi>G</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>G</mi></msub><mo>,</mo>
				<msub><mi>B</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>B</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_DST_COLOR</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow><mo>(</mo>
				<msub><mi>R</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>R</mi></msub><mo>,</mo>
				<msub><mi>G</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>G</mi></msub><mo>,</mo>
				<msub><mi>B</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>B</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_ONE_MINUS_DST_COLOR</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow>
			    <mo>(</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn>
			    <mo>)</mo>
			    <mo>-</mo>
			    <mo>(</mo>
				<msub><mi>R</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>R</mi></msub><mo>,</mo>
				<msub><mi>G</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>G</mi></msub><mo>,</mo>
				<msub><mi>B</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>B</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_SRC_ALPHA</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow><mo>(</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_ONE_MINUS_SRC_ALPHA</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow>
			    <mo>(</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn>
			    <mo>)</mo>
			    <mo>-</mo>
			    <mo>(</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>s</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_DST_ALPHA</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow><mo>(</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_ONE_MINUS_DST_ALPHA</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow>
			    <mo>(</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn><mo>,</mo>
				<mn>1</mn>
			    <mo>)</mo>
			    <mo>-</mo>
			    <mo>(</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
				<msub><mi>A</mi><mi>d</mi></msub><mo>/</mo><msub><mi>k</mi><mi>A</mi></msub>
			    <mo>)</mo></mrow></math>
			</td></tr><tr><td>
			    <code class="constant">GL_SRC_ALPHA_SATURATE</code>
			</td><td class="center">
			    <math overflow="scroll"><mrow><mo>(</mo>
				<mi>i</mi><mo>,</mo>
				<mi>i</mi><mo>,</mo>
				<mi>i</mi><mo>,</mo>
				<mn>1</mn>
			    <mo>)</mo></mrow></math>
			</td></tr></tbody></table></div><p>In the table,</p><div class="informalequation"><math overflow="scroll"><mrow>
		<mi>i</mi><mo>=</mo><mo>min</mo><mo>(</mo>
		    <msub><mi>A</mi><mi>s</mi></msub><mo>,</mo>
		    <msub><mi>k</mi><mi>A</mi></msub><mo>-</mo><msub><mi>A</mi><mi>d</mi></msub>
		    <mo>)</mo>
		    <mo>/</mo>
		    <msub><mi>k</mi><mi>A</mi></msub>
	    </mrow></math></div><p>To determine the blended values of a pixel, the system
	uses the following equations:</p><div class="informalequation"><math overflow="scroll"><mtable>
	    <mtr><mtd>
		<msub><mi>R</mi><mi>d</mi></msub>
		<mgroupalign></mgroupalign>
		<mo>=</mo>
		<mgroupalign></mgroupalign>
		<mo>min</mo><mo>(</mo>
		<msub><mi>k</mi><mi>R</mi></msub><mo>,</mo>
		<msub><mi>R</mi><mi>s</mi></msub>
		<msub><mi>s</mi><mi>R</mi></msub><mo>+</mo>
		<msub><mi>R</mi><mi>d</mi></msub>
		<msub><mi>d</mi><mi>R</mi></msub>
		<mo>)</mo>
	    </mtd></mtr>
	    <mtr><mtd>
		<msub><mi>G</mi><mi>d</mi></msub>
		<mgroupalign></mgroupalign>
		<mo>=</mo>
		<mgroupalign></mgroupalign>
		<mo>min</mo><mo>(</mo>
		<msub><mi>k</mi><mi>G</mi></msub><mo>,</mo>
		<msub><mi>G</mi><mi>s</mi></msub>
		<msub><mi>s</mi><mi>G</mi></msub><mo>+</mo>
		<msub><mi>G</mi><mi>d</mi></msub>
		<msub><mi>d</mi><mi>G</mi></msub>
		<mo>)</mo>
	    </mtd></mtr>
	    <mtr><mtd>
		<msub><mi>B</mi><mi>d</mi></msub>
		<mgroupalign></mgroupalign>
		<mo>=</mo>
		<mgroupalign></mgroupalign>
		<mo>min</mo><mo>(</mo>
		<msub><mi>k</mi><mi>B</mi></msub><mo>,</mo>
		<msub><mi>B</mi><mi>s</mi></msub>
		<msub><mi>s</mi><mi>B</mi></msub><mo>+</mo>
		<msub><mi>B</mi><mi>d</mi></msub>
		<msub><mi>d</mi><mi>B</mi></msub>
		<mo>)</mo>
	    </mtd></mtr>
	    <mtr><mtd>
		<msub><mi>A</mi><mi>d</mi></msub>
		<mgroupalign></mgroupalign>
		<mo>=</mo>
		<mgroupalign></mgroupalign>
		<mo>min</mo><mo>(</mo>
		<msub><mi>k</mi><mi>A</mi></msub><mo>,</mo>
		<msub><mi>A</mi><mi>s</mi></msub>
		<msub><mi>s</mi><mi>A</mi></msub><mo>+</mo>
		<msub><mi>A</mi><mi>d</mi></msub>
		<msub><mi>d</mi><mi>A</mi></msub>
		<mo>)</mo>
	    </mtd></mtr>
	</mtable></math></div><p>Despite the apparent precision of the above equations,
	blending arithmetic is not exactly specified, because blending
	operates with imprecise integer color values. However, a blend
	factor that should be equal to 1 is guaranteed not to modify
	its multiplicand, and a blend factor equal to 0 reduces its
	multiplicand to 0. For example, when <em class="parameter"><code>sfactor</code></em>
	is <code class="constant">GL_SRC_ALPHA</code>,
	<em class="parameter"><code>dfactor</code></em> is
	<code class="constant">GL_ONE_MINUS_SRC_ALPHA</code>, and
	<math overflow="scroll"><msub><mi>A</mi><mi>s</mi></msub></math>
	is equal to
	<math overflow="scroll"><msub><mi>k</mi><mi>A</mi></msub></math>,
	the equations reduce to simple replacement:</p><div class="informalequation"><math overflow="scroll"><mtable>
	    <mtr><mtd>
		<msub><mi>R</mi><mi>d</mi></msub>
		<mgroupalign></mgroupalign>
		<mo>=</mo>
		<mgroupalign></mgroupalign>
		<msub><mi>R</mi><mi>s</mi></msub>
	    </mtd></mtr>
	    <mtr><mtd>
		<msub><mi>G</mi><mi>d</mi></msub>
		<mgroupalign></mgroupalign>
		<mo>=</mo>
		<mgroupalign></mgroupalign>
		<msub><mi>G</mi><mi>s</mi></msub>
	    </mtd></mtr>
	    <mtr><mtd>
		<msub><mi>B</mi><mi>d</mi></msub>
		<mgroupalign></mgroupalign>
		<mo>=</mo>
		<mgroupalign></mgroupalign>
		<msub><mi>B</mi><mi>s</mi></msub>
	    </mtd></mtr>
	    <mtr><mtd>
		<msub><mi>A</mi><mi>d</mi></msub>
		<mgroupalign></mgroupalign>
		<mo>=</mo>
		<mgroupalign></mgroupalign>
		<msub><mi>A</mi><mi>s</mi></msub>
	    </mtd></mtr>
	</mtable></math></div><p>
	<code class="function">glBlendFunc</code> operates on all pixel write operations,
	including the scan conversion of points, lines, and polygons.
	<code class="function">glBlendFunc</code> does not affect
	<a class="citerefentry" href="glClear"><span class="citerefentry"><span class="refentrytitle">glClear</span></span></a>.
	</p></div><div class="refsect1" title="Examples"><a id="examples"></a><h2>Examples</h2><p>Transparency is best implemented using
	<code class="function">glBlendFunc</code>(<code class="constant">GL_SRC_ALPHA</code>,
	<code class="constant">GL_ONE_MINUS_SRC_ALPHA</code>)
	with primitives sorted from farthest to nearest. Note that
	this transparency calculation does not require the presence of
	alpha bitplanes in the color buffer.</p><p><code class="function">glBlendFunc</code>(<code class="constant">GL_SRC_ALPHA</code>,
	<code class="constant">GL_ONE_MINUS_SRC_ALPHA</code>)
	is also useful for rendering antialiased points and lines.
	</p></div><div class="refsect1" title="Notes"><a id="notes"></a><h2>Notes</h2><p>Incoming (source) alpha is correctly thought of as a
	material opacity, ranging from 1.0
	(<math overflow="scroll"><msub><mi>k</mi><mi>A</mi></msub></math>),
	representing complete opacity, to 0.0 (0), representing
	complete transparency.</p></div><div class="refsect1" title="Errors"><a id="errors"></a><h2>Errors</h2><p><code class="constant">GL_INVALID_ENUM</code> is generated if either
	<em class="parameter"><code>sfactor</code></em> or <em class="parameter"><code>dfactor</code></em>
	is not an accepted value.</p></div><div class="refsect1" title="See Also"><a id="seealso"></a><h2>See Also</h2><p>
	    <a class="citerefentry" href="glAlphaFunc"><span class="citerefentry"><span class="refentrytitle">glAlphaFunc</span></span></a>,
	    <a class="citerefentry" href="glClear"><span class="citerefentry"><span class="refentrytitle">glClear</span></span></a>,
	    <a class="citerefentry" href="glDepthFunc"><span class="citerefentry"><span class="refentrytitle">glDepthFunc</span></span></a>,
	    <a class="citerefentry" href="glEnable"><span class="citerefentry"><span class="refentrytitle">glEnable</span></span></a>,
	    <a class="citerefentry" href="glLogicOp"><span class="citerefentry"><span class="refentrytitle">glLogicOp</span></span></a>,
	    <a class="citerefentry" href="glStencilFunc"><span class="citerefentry"><span class="refentrytitle">glStencilFunc</span></span></a>
	</p></div><div class="refsect1" title="Copyright"><a id="copyright"></a><h2>Copyright</h2><p>
	    Copyright © 2003-2004
	    Silicon Graphics, Inc. This document is licensed under the SGI
	    Free Software B License. For details, see
	    <a class="ulink" href="http://oss.sgi.com/projects/FreeB/" target="_top">http://oss.sgi.com/projects/FreeB/</a>.
        </p></div></div>
